import React, { useState, useEffect, PureComponent, useContext, createContext, useReducer, memo, useCallback, useMemo, useRef } from 'react'
export default function Test() {
  const [counter, setCounter] = useState(0)
  // 1.当前返回Ref对象在组件的整个生命周期中保持不变
  const numRef = useRef(counter)
  console.log(numRef)
  useEffect(() => {
    numRef.current = counter
  }, [counter])

  return (
    <>
      <div> 上次的值：{numRef.current}</div>
      <div> 此时的值：{counter}</div>
      <hr />
      <button onClick={() => setCounter(counter + 1)}>点击</button>
      <hr />
    </>
  )
}
